#include "top_controller.h"
#include "model/b_spline3.h"

TopController::TopController(View* v,Model* m)
	:Controller2D(v,m){

}

TopController::~TopController(){

}

void TopController::keyboard(unsigned char key,float x ,float y){
	if(key=='c'){
		static_cast<BSpline3*>(this->model)->closeBSpline();
	}
}

void TopController::mousePressed(int key,int state,float x ,float y){
	CurveModel& curve=(CurveModel&)(*model);
	Controller2D::mousePressed(key,state,x,y);
	if (!this->drag.first && state==GLUT_DOWN && key==GLUT_LEFT_BUTTON){
		curve.addPoint( Point(x,y) );
		curve.calculatePoints();
	}else if (this->drag.first && key==GLUT_RIGHT_BUTTON && state==GLUT_DOWN){
		curve.removePoint(this->drag.second);
		this->drag=std::pair<bool,Point>(false,Point(0,0));
			curve.calculatePoints();
	}else if(this->drag.first && key==GLUT_LEFT_BUTTON && state==GLUT_UP){
		Point p(x,y);
		curve.movePoint(drag.second,p);
		calculatePoints();
		this->drag=std::pair<bool,Point>(false,Point(0,0));
	}
}
